<%@ page import="com.po.Envelope" %>
<%@ page import="java.util.List" %>
<%@ page import="com.po.User" %>
<%@page isErrorPage="true" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<title>公开的信封</title>

<%
    HttpSession session1 = request.getSession(false);
    if (session1 == null || session1.getAttribute("id") == null) {
        response.sendRedirect(request.getContextPath() + "/index.jsp");
    }
    List<Envelope> envelopes = (List<Envelope>) request.getAttribute("list");
    List<String> fname = (List<String>) request.getAttribute("fname");
%>

<div style="text-align: center">
    <form action="<%=request.getContextPath()%>/selectEnvelope" method="post">
        根据信封名字搜索信封:<input name="envelope_name" type="text">
        <input type="submit" value="搜索">
    </form>
</div>
<br><br><br>
<table>
    <tr>
        <td><h3>信封主人</h3></td>
        <td><h3>添加好友</h3></td>
        <td><h3>信封名字</h3></td>
        <%
            if ("administrator".equals(session.getAttribute("duty"))) {
        %>
        <td><h3>管理员权限</h3></td>
        <%
            }
        %>
    </tr>
    <%
        for (Envelope envelope : envelopes) {
    %>
    <tr>

        <td><%=envelope.getUser_name()%><%=envelope.getUser_sex()%>
        </td>
        <%
            if (!fname.contains(envelope.getUser_name())) {
        %>

        <td>
            <button onclick="window.location.href='<%=request.getContextPath()%>/addFriends?user_name=<%=envelope.getUser_name()%>'"
                    type="button">添加好友
            </button>
        </td>
        <%
        } else {
        %>
        <td>
            <button>已是好友</button>
        </td>
        <%
            }
        %>
        <td><%=envelope.getName()%>
        </td>
        <td>
            <button onclick="window.location.href='<%=request.getContextPath()%>/function/selectNotes?envelope_id=<%=envelope.getEnvelope_id()%>&envelope_name=<%=envelope.getName()%>'"
                    type="button">查看信封内容
            </button>
        </td>

    </tr>
    <%
        }
    %>
</table>
<style>
    table {
        width: 500px;
        margin: auto;
        border: pink 1px solid;
        border-spacing: 0px;
        border-collapse: collapse;
    }

    td {
        border: pink 1px solid;
    }

    body {
        background-image: url("../picture/new.jpg");
        background-repeat: no-repeat;
        background-attachment: fixed;
        background-position: center center;
        background-size: 100% 100%;
    }
</style>
<a href="<%=request.getContextPath()%>/success.jsp">返回功能列表</a>
